package com.bltec.emergency.mapper;

import com.bltec.emergency.model.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Insert("insert into sys_user (username,password,sex,email,role_id,create_by,create_time,enable) values(#{username},#{password},#{sex},#{email},#{roleId},#{createBy},#{createTime},#{enable})")
    boolean insert(User user);

    @Delete("delete from sys_user where username=#{username}")
    boolean deleteByUsername(String username);

    @Update("update sys_user set enable=0 where id=#{id} and id<>1")
    boolean setDisableById(Long id);

    @Update("update sys_user set username=#{username},tel=#{tel},phone=#{phone},department_id=#{departmentId},position=#{position},sex=#{sex},email=#{email},role_id=#{roleId},update_by=#{updateBy},update_time=#{updateTime} where id=#{id}")
    boolean updateUserById(User user);

    @Select("select * from sys_user where username =#{username} and enable=1")
    User getUserByUsername(String username);

    @Select("select id from sys_user where username =#{username} and enable=1")
    Long getIdByUserName(String username);

    @Select("select role_id from sys_user where username =#{username} and enable=1")
    Long getRoleIdByUserName(String username);

    @Select("select password from sys_user where username =#{username} and enable=1")
    String getPassWordByUserName(String username);

    @Select("select * from sys_user where id =#{id} and enable=1")
    User getUserById(Long id);

    @Select("select * from sys_user where enable=1")
    List<User> selectAll();

    @Select("select username from sys_user where enable=1")
    List<String> selectAllUsername();


}
